import { createRouter, createWebHashHistory } from 'vue-router'
import { basicRoutes } from '@/router/basic'
import { businessRoutes } from '@/router/business' 
import { Toast } from 'vant'
import store from '@/store'
// 定义路由配置
const routes = [
	// 标准产品提供的默认路由
	...basicRoutes,
	// 二次开发中业务模块提供路由
	...businessRoutes
]
// 创建路由实例
const router = createRouter({
  // history模式
	history: createWebHashHistory(),
  routes,
})
/**
 * 路由白名单
 */
const whiteSpace = ['login', 'loginScan', 'mine','index', 'menu', 'audit', 'auditLog', 'initApp', 'loginScan']
router.beforeEach((to, from, next) => {
	const hasAuth = store.getters.menus.some((menu) => {
		return menu.beanId === to.name || menu.beanId + 'Detail' === to.name 
	})
  if(whiteSpace.indexOf(to.name) === -1 && !hasAuth) {
		Toast.fail({
			message: '您没有操作权限',
			duration: 3000
		})
	}
  else next()
})

export default router